package com.ruoyi.buss.customer.service.impl;

import java.util.*;

import com.ruoyi.buss.customer.domain.ReportywxxLsb;
import com.ruoyi.buss.grid.carInfo.domain.CarInfo;
import com.ruoyi.buss.grid.carInfo.mapper.CarInfoMapper;
import com.ruoyi.buss.grid.zysc.domain.DataWgZyscKh;
import com.ruoyi.buss.grid.zysc.mapper.DataWgZyscKhMapper;
import com.ruoyi.buss.qmcy.mapper.QmcyCustPersonalInfoMapper;
import com.ruoyi.buss.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.buss.customer.domain.DataCustomerInfo;
import com.ruoyi.buss.customer.domain.DataWgJtcy;
import com.ruoyi.buss.customer.mapper.DataCustomerInfoMapper;
import com.ruoyi.buss.customer.mapper.DataCustomerRecordMapper;
import com.ruoyi.buss.customer.mapper.DataWgJtcyMapper;
import com.ruoyi.buss.customer.service.IDataCustomerInfoService;
import com.ruoyi.buss.grid.cj.domain.DataCustomerInfoVO;
import com.ruoyi.buss.grid.cj.domain.DataWgWgcj;
import com.ruoyi.buss.grid.cj.mapper.DataWgWgcjMapper;
import com.ruoyi.buss.grid.sh.domain.DataGtgsh;
import com.ruoyi.buss.grid.sh.mapper.DataGtgshMapper;
import com.ruoyi.buss.grid.sq.domain.DataWgWgsq;
import com.ruoyi.buss.grid.sq.mapper.DataWgWgsqMapper;
import com.ruoyi.buss.group.domain.DataCustomerGroup;
import com.ruoyi.buss.group.domain.DataCustomerGroupRelation;
import com.ruoyi.buss.group.mapper.DataCustomerGroupMapper;
import com.ruoyi.buss.group.mapper.DataCustomerGroupRelationMapper;
import com.ruoyi.buss.task.domain.DataTaskExRecord;
import com.ruoyi.buss.task.domain.DataTaskExRecordBack;
import com.ruoyi.buss.task.domain.DataUserTaskRelation;
import com.ruoyi.buss.task.mapper.DataTaskExRecordBackMapper;
import com.ruoyi.buss.task.mapper.DataTaskExRecordMapper;
import com.ruoyi.buss.task.mapper.DataUserTaskRelationMapper;
import com.ruoyi.common.core.exception.CustomException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;

import javax.annotation.Resource;

/**
 * 客户信息Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@Service
public class DataCustomerInfoServiceImpl implements IDataCustomerInfoService {
    private Logger logger = LoggerFactory.getLogger(DataCustomerInfoServiceImpl.class);
    @Resource
    private DataCustomerInfoMapper dataCustomerInfoMapper;

    @Resource
    private DataCustomerGroupMapper dataCustomerGroupMapper;

    @Resource
    private DataCustomerGroupRelationMapper dataCustomerGroupRelationMapper;

    @Resource
    private DataWgWgcjMapper dataWgWgcjMapper;

    @Resource
    private DataWgWgsqMapper dataWgWgsqMapper;

    @Resource
    private DataWgJtcyMapper dataWgJtcyMapper;

    @Resource
    private DataGtgshMapper dataGtgshMapper;

    @Resource
    private DataUserTaskRelationMapper dataUserTaskRelationMapper;

    @Resource
    private DataTaskExRecordMapper dataTaskExRecordMapper;

    @Resource
    private DataTaskExRecordBackMapper dataTaskExRecordBackMapper;

    @Resource
    private DataCustomerRecordMapper dataCustomerRecordMapper;

    @Resource
    private QmcyCustPersonalInfoMapper qmcyCustPersonalInfoMapper;

    @Resource
    private DataWgZyscKhMapper dataWgZyscKhMapper;

    @Resource
    private CarInfoMapper carInfoMapper;

    /**
     * 查询客户信息列表
     *
     * @param dataCustomerInfo 客户信息
     * @return 客户信息
     */
    @Override
    public List<DataCustomerInfo> selectDataCustomerInfoList(DataCustomerInfo dataCustomerInfo, LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();

        /** 如果查询带条件 【姓名，身份证，手机】，则可以查询所有客户 */
        if (StringUtils.isNotEmpty(dataCustomerInfo.getName()) ||
                StringUtils.isNotEmpty(dataCustomerInfo.getIdCard()) ||
                StringUtils.isNotEmpty(dataCustomerInfo.getPhone())
        ) {
            logger.info("此处查询带条件，跳过");
        } else {
            // 如果是admin用户不做处理
            if (userInfo.getRoles().contains("zhhz")) {
                dataCustomerInfo.setOrgId(orgId);
            } else if (userInfo.getRoles().contains("common")) {
                dataCustomerInfo.setOrgId(orgId);
                dataCustomerInfo.setUserId(userId);
            }
        }

        List<DataCustomerInfo> doList = new ArrayList<DataCustomerInfo>();
        //0代表存量客户 管户信息需从DATA_CUSTOMER_BANK_RELATION取     1表示新增客户没有发生业务信息 从DATA_CUSTOMER_INFO取管户
        if ("0".equals(dataCustomerInfo.getIfStock())) {
            doList = dataCustomerInfoMapper.selectDataCustomerInfoList(dataCustomerInfo);
        } else {
            doList = dataCustomerInfoMapper.selectCustomerInfoList(dataCustomerInfo);
        }

		/*for (DataCustomerInfo custInfo : doList) {
			// 获取群体
			List<DataCustomerGroup> groupLabel = custInfo.getGroupLabel();
			if (!ListUtil.isNullOrEmpty(groupLabel)) {
				custInfo.setHeadPic(groupLabel.get(0).getGroupCode());
			} else {
				custInfo.setHeadPic(dataCustomerInfo.getSex());
			}
		}*/

        return doList;
    }

    @Override
    public Integer ifStock(DataCustomerInfo dataCustomerInfo) {


        int ifStock = dataCustomerInfoMapper.ifStock(dataCustomerInfo);

        return ifStock;
    }

    /**
     * 查询客户信息
     *
     * @param idCard 客户信息IDCard
     * @return 客户信息
     */
    @Override
    public DataCustomerInfo selectDataCustomerInfoById(String idCard) {

        DataCustomerInfo dataCustomerInfo = dataCustomerInfoMapper.selectDataCustomerInfoByIdCard(idCard);

        if (dataCustomerInfo == null) {
            throw new CustomException("未查询到该客户信息,请联系管理员");
        }

        DataCustomerGroupRelation groupLabel = dataCustomerInfo.getGroupLabel();
        if (groupLabel != null) {
            /**
             * TODO 切换标签库之后，如何修改app中标签头像
             */
//			dataCustomerInfo.setHeadPic(groupLabel.getCusName());
            dataCustomerInfo.setHeadPic(dataCustomerInfo.getSex());
        } else {
            dataCustomerInfo.setHeadPic(dataCustomerInfo.getSex());
        }

        return dataCustomerInfo;
    }

    /**
     * 新增客户信息
     *
     * @param dataCustomerInfo 客户信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertDataCustomerInfo(DataCustomerInfo dataCustomerInfo, LoginUser userInfo) {
        int flag = 0;
        //公共信息
        String name = dataCustomerInfo.getName();
        String idCard = dataCustomerInfo.getIdCard();
        String phone = dataCustomerInfo.getPhone();

        dataCustomerInfo.setCreateTime(DateUtils.getNowDate());

        // 判断参数是否传入管户，如果未传，默认当前客户经理
        if (StringUtils.isEmpty(dataCustomerInfo.getOrgId()) || StringUtils.isEmpty(dataCustomerInfo.getUserId())) {
            if (userInfo.getSysUser().getDept().getOrgId() == null || userInfo.getSysUser().getUserName() == null) {
                throw new CustomException("登录信息失效,请重新登录!");
            }

            dataCustomerInfo.setOrgId(userInfo.getSysUser().getDept().getOrgId());
            dataCustomerInfo.setUserId(userInfo.getSysUser().getUserName());
            dataCustomerInfo.setManagerId(userInfo.getSysUser().getUserName());
        }

        // 判断当前证件是否为身份证
        Boolean bool = PatternUtils.isIDNumber(dataCustomerInfo.getIdCard());
        Map<String, Object> map = new HashMap<>();
        if (bool) {
            // 根据身份证获取性别与年龄
            if (dataCustomerInfo.getIdCard().length() == 15) {
                map = CardUtil.getCarInfo15W(dataCustomerInfo.getIdCard());
            } else {
                map = CardUtil.getCarInfo(dataCustomerInfo.getIdCard());
            }
            dataCustomerInfo.setAge(Integer.parseInt(map.get("age").toString()));
            dataCustomerInfo.setSex(map.get("sex").toString());
        } else {
            dataCustomerInfo.setSex("1");// 默认性别
            dataCustomerInfo.setAge(0);// 默认年龄
        }

        // 初始化 与户主关系
        if (StringUtils.isEmpty(dataCustomerInfo.getYhzgx())) {
            dataCustomerInfo.setYhzgx("1");// 客户默认户主
        }

        /**
         * 查询家庭成员信息 如果没有家庭成员，则初始化家庭成员
         */
        DataWgJtcy dataWgJtcy = dataWgJtcyMapper.selectDataWgJtcyByIdCard(dataCustomerInfo.getIdCard());
        if (dataWgJtcy == null) {
            dataWgJtcy = new DataWgJtcy();
            if (dataCustomerInfo.getHjbh() == null) {
                dataCustomerInfo.setHjbh(dataCustomerInfo.getIdCard());
            }
            dataWgJtcy.setHjbh(dataCustomerInfo.getHjbh());
            if (dataCustomerInfo.getHzxm() == null) {
                dataCustomerInfo.setHzxm(dataCustomerInfo.getName());
            }
            dataWgJtcy.setHzxm(dataCustomerInfo.getHzxm());
            dataWgJtcy.setIdCard(dataCustomerInfo.getIdCard());
            dataWgJtcy.setName(dataCustomerInfo.getName());
            dataWgJtcy.setSex(dataCustomerInfo.getSex());
            dataWgJtcy.setAge(String.valueOf(dataCustomerInfo.getAge()));
            dataWgJtcy.setYhzgx(dataCustomerInfo.getYhzgx());
            dataWgJtcy.setDelFlag("0");
            dataWgJtcy.setCreateTime(DateUtils.getNowDate());
            flag = dataWgJtcyMapper.insertDataWgJtcy(dataWgJtcy);
        }

        /**
         * 修改群体信息
         * 此时多个标签信息直接会被转为字符串存入数据库，只会产生一条数据，直接更新即可
         */
        DataCustomerGroupRelation relationCondition = dataCustomerInfo.getGroupLabel();
        if (relationCondition != null) {
            relationCondition.setStatus("1");// 1表示有效
            relationCondition.setIdCard(dataCustomerInfo.getIdCard());
            relationCondition.setUserId(dataCustomerInfo.getUserId());
            relationCondition.setOrgId(dataCustomerInfo.getOrgId());

            DataCustomerGroupRelation groupRelation =
                    dataCustomerGroupRelationMapper.selectDataCustomerGroupRelationById(dataCustomerInfo.getIdCard());
            if (groupRelation != null) {
                relationCondition.setUpdateTime(DateUtils.getNowDate());
                flag = dataCustomerGroupRelationMapper.updateDataCustomerGroupRelation(relationCondition);
            } else {
                relationCondition.setCreateTime(DateUtils.getNowDate());
                flag = dataCustomerGroupRelationMapper.insertDataCustomerGroupRelation(relationCondition);
            }

        }

        // 判断是否传入了社区客户信息
        DataWgWgsq dataWgWgsq = new DataWgWgsq();
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgWgsq())) {
            dataWgWgsq = dataCustomerInfo.getDataWgWgsq().get(0);
//			if (StringUtils.isEmpty(dataWgWgsq.getIdCard())) {
            dataWgWgsq.setIdCard(idCard);
//			}
            if (dataCustomerInfo.getHjbh() == null) {
                dataCustomerInfo.setHjbh(dataCustomerInfo.getIdCard());
            }
            if (dataCustomerInfo.getHzxm() == null) {
                dataCustomerInfo.setHzxm(dataCustomerInfo.getName());
            }
            dataWgWgsq.setHjbh(dataCustomerInfo.getHjbh());
            dataWgWgsq.setHzxm(dataCustomerInfo.getHzxm());
            dataWgWgsq.setYhzgx(dataCustomerInfo.getYhzgx());
            dataWgWgsq.setSex(dataCustomerInfo.getSex());
            dataWgWgsq.setAge(dataCustomerInfo.getAge());
            dataWgWgsq.setPhone(dataCustomerInfo.getPhone());
            dataWgWgsq.setName(name);
            dataWgWgsq.setCustomerType(dataCustomerInfo.getCustomerType());
            dataWgWgsq.setCreateTime(DateUtils.getNowDate());
            dataWgWgsq.setCreateUser(dataCustomerInfo.getUserId());
            dataWgWgsq.setOrgId(dataCustomerInfo.getOrgId());
            dataWgWgsq.setManagerId(dataCustomerInfo.getUserId());
            dataCustomerInfo.setIfWgsq("1");
            if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataGtgsh())) {
                dataWgWgsq.setIfGtgsh("1");
            }

            if (StringUtils.isEmpty(dataWgWgsq.getAddress())) {
                dataWgWgsq.setAddress(dataWgWgsq.getJzAddress());
            }
            // 判断是否传入户籍编号与户主姓名，如果不存在，则初始化
            if (StringUtils.isEmpty(dataWgWgsq.getHjbh())) {
                dataWgWgsq.setHjbh(dataCustomerInfo.getIdCard());
            }
            if (StringUtils.isEmpty(dataWgWgsq.getHzxm())) {
                dataWgWgsq.setHzxm(dataCustomerInfo.getName());
            }
            // 先判断社区表中是否已存在该客户 不同小区可以重复
            List<DataWgWgsq> wgsq = dataWgWgsqMapper.selectDataWgWgsq(dataWgWgsq);
            if (!ListUtil.isNullOrEmpty(wgsq)) {
                logger.info("当前小区已存在该客户，身份证号码={}", dataCustomerInfo.getIdCard());
            } else {
                // 插入社区表
                flag = dataWgWgsqMapper.insertDataWgWgsq(dataWgWgsq);
            }
        }


        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataGtgsh())) {
            // 先判断个体工商户是否已存在该客户 不同小区可以重复
            DataGtgsh dataGtgsh = dataCustomerInfo.getDataGtgsh().get(0);
            DataGtgsh dataGtgshs = dataGtgshMapper.selectDataGtgshByIdCard(dataCustomerInfo.getIdCard(), dataGtgsh.getSssjsq(), dataGtgsh.getSssq());
            if (dataGtgshs == null) {
                //				if (StringUtils.isEmpty(dataGtgsh.getZjhm())) {
                dataGtgsh.setZjhm(idCard);
//				}
                dataGtgsh.setId(GetOnlyId.getOnlyId());
                dataGtgsh.setPhone(phone);
                dataGtgsh.setOrgId(dataCustomerInfo.getOrgId());
                dataGtgsh.setUserId(dataCustomerInfo.getUserId());
                dataGtgsh.setCreateTime(DateUtils.getNowDate());
                dataGtgsh.setCreateUser(dataCustomerInfo.getUserId());
                if(StringUtils.isEmpty(dataCustomerInfo.getId())){
                    dataGtgsh.setIdCard(dataCustomerInfo.getIdCard());
                } else {
                    dataGtgsh.setIdCard(dataCustomerInfo.getId());
                }

                //判断商户是否上传居住地址 如果不存在，则初始化
                if (StringUtils.isEmpty(dataGtgsh.getAddress())) {
                    dataGtgsh.setAddress(dataGtgsh.getJydz());
                }
                //更新存量表中  是否个体工商户 0否1是
                dataCustomerInfo.setIfGtgsh("1");
                // 插入个体工商户表
                flag = dataGtgshMapper.insertDataGtgsh(dataGtgsh);
            } else {
                //新增客户时，如果已经存在个体工商户，则更新IDCARD字段，关联data_customer_info表
                dataGtgshs.setIdCard(dataCustomerInfo.getId());
                flag = dataGtgshMapper.updateDataGtgsh(dataGtgshs);
            }

        }

        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgZyscKh())) {
//		public List<DataWgZyscKh> selectDataWgZyscKhList(DataWgZyscKh dataWgZyscKh);
//		DataWgZyscKh dataWgZyscKh = dataWgZyscKhMapper.selectDataWgZyscKhByIdCard(dataCustomerInfo.getIdCard());
            DataWgZyscKh dataWgZyscKh = new DataWgZyscKh();
            dataWgZyscKh.setIdCard(dataCustomerInfo.getIdCard());
            dataWgZyscKh.setMarketId(dataCustomerInfo.getDataWgZyscKh().get(0).getMarketId());

            List<DataWgZyscKh> dataWgZyscKhs = dataWgZyscKhMapper.selectDataWgZyscKhList(dataWgZyscKh);
            if (!ListUtil.isNullOrEmpty(dataWgZyscKhs)) {
                logger.info("当前表中已存在该客户，证件号码={}", dataCustomerInfo.getIdCard());
            } else {
//				if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgZyscKh())) {
                dataWgZyscKh = dataCustomerInfo.getDataWgZyscKh().get(0);
                dataWgZyscKh.setIdCard(dataCustomerInfo.getIdCard());
                dataWgZyscKh.setName(name);
                dataWgZyscKh.setPhone(phone);
                dataWgZyscKh.setManagerId(dataCustomerInfo.getUserId());
                dataWgZyscKh.setOrgId(dataCustomerInfo.getOrgId());
                dataWgZyscKh.setCreateUser(dataCustomerInfo.getUserId());
                dataWgZyscKh.setCreateTime(DateUtils.getNowDate());
                if (StringUtils.isEmpty(dataWgZyscKh.getZhenshiJingdu()) || StringUtils.isEmpty(dataWgZyscKh.getZhenshiWeidu())) {
                    throw new CustomException("专业市场定位地址为空,请重新定位!!");
                }
                //判断商户是否上传居住地址 如果不存在，则初始化
                if (StringUtils.isEmpty(dataWgZyscKh.getDwAddress())) {
                    dataWgZyscKh.setDwAddress(dataCustomerInfo.getAddress());
                }
                flag = dataWgZyscKhMapper.insertDataWgZyscKh(dataWgZyscKh);
//				}
            }
        }
        /**
         * 判断存量客户信息表中是否存在，如果不存在，则插入
         */
        DataCustomerInfo dataCustomerInfoOne = dataCustomerInfoMapper
                .selectDataCustomerInfoByIdCard(dataCustomerInfo.getIdCard());
        if (dataCustomerInfoOne == null) {
            dataCustomerInfo.setId(dataCustomerInfo.getIdCard());
            dataCustomerInfo.setCreateTime(DateUtils.getNowDate());
            dataCustomerInfo.setStatus("1");
            dataCustomerInfo.setIfFenpei("0");
            dataCustomerInfo.setIsPublic("0");
            dataCustomerInfo.setCustomerLevelZh("0");
            dataCustomerInfo.setCreateUser(userInfo.getSysUser().getUserName());
            dataCustomerInfo.setIdCardShow(dataCustomerInfo.getIdCard());
            if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgWgcj())) {
                dataCustomerInfo.setIfWgcj("1");
            }
            //0存量  1新增
            dataCustomerInfo.setIfStock("1");
            if (dataCustomerInfo.getIdCard().length() == 18) {
                dataCustomerInfo.setBirthday(dataCustomerInfo.getIdCard().substring(10, 14));
            }
            flag = dataCustomerInfoMapper.insertDataCustomerInfo(dataCustomerInfo);
        } else {
            throw new CustomException("当前客户信息已存在,管护人为:" + dataCustomerInfoOne.getUserId());
        }

        /**
         * 判断网格村居客户是否存在，如果不存在，则插入
         */
        DataWgWgcj dataWgWgcj = new DataWgWgcj();
        dataWgWgcj.setIdCard(idCard);
        List<DataWgWgcj> dataWgWgcjList = dataWgWgcjMapper.selectDataWgWgcjList(dataWgWgcj);
        if (ListUtil.isNullOrEmpty(dataWgWgcjList)) {
            if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgWgcj())) {
                dataWgWgcj = dataCustomerInfo.getDataWgWgcj().get(0);
                // TOWN VILLAGE 不能为空
//			if (StringUtils.isEmpty(dataWgWgcj.getIdCard())) {
                dataWgWgcj.setIdCard(idCard);
//			}
                if (dataCustomerInfo.getHjbh() == null) {
                    dataCustomerInfo.setHjbh(dataCustomerInfo.getIdCard());
                }
                dataWgWgcj.setHjbh(dataCustomerInfo.getHjbh());
                if (dataCustomerInfo.getHzxm() == null) {
                    dataCustomerInfo.setHzxm(dataCustomerInfo.getName());
                }
                dataWgWgcj.setHzxm(dataCustomerInfo.getHzxm());

                dataWgWgcj.setIdCard(idCard);
                dataWgWgcj.setName(name);
                dataWgWgcj.setYhzgx(dataCustomerInfo.getYhzgx());
                dataWgWgcj.setOrgId(dataCustomerInfo.getOrgId());
                dataWgWgcj.setManagerId(dataCustomerInfo.getUserId());
                dataWgWgcj.setSex(dataCustomerInfo.getSex());
                dataWgWgcj.setAge(dataCustomerInfo.getAge());
                dataWgWgcj.setPhone(dataCustomerInfo.getPhone());
                dataWgWgcj.setCustomerType(dataCustomerInfo.getCustomerType());
                dataWgWgcj.setCreateTime(DateUtils.getNowDate());
                //判断网格村居是否上传居住地址 如果不存在，则初始化
                if (StringUtils.isEmpty(dataWgWgcj.getAddress())) {
                    dataWgWgcj.setAddress(dataCustomerInfo.getAddress());
                }
                // 判断是否传入户籍编号与户主姓名，如果不存在，则初始化
                if (StringUtils.isEmpty(dataWgWgcj.getHjbh())) {
                    dataWgWgcj.setHjbh(dataCustomerInfo.getIdCard());
                }
                if (StringUtils.isEmpty(dataWgWgcj.getHzxm())) {
                    dataWgWgcj.setHzxm(dataCustomerInfo.getName());
                }

                flag = dataWgWgcjMapper.insertDataWgWgcj(dataWgWgcj);
            }
        }


        //判断是否新增信息的同时添加了车辆信息
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getCarInfoList())) {
            for (CarInfo carInfo : dataCustomerInfo.getCarInfoList()) {
                CarInfo car = new CarInfo();
                car.setCarNumber(carInfo.getCarNumber());
                car.setIdCard(carInfo.getIdCard());
                List<CarInfo> carInfoList = carInfoMapper.selectCarInfoList(car);
                if (ListUtil.isNullOrEmpty(carInfoList)) {
                    carInfo.setId(GetOnlyId.getOnlyId());
                    carInfo.setIdCard(idCard);
                    carInfo.setName(name);
                    carInfo.setStatus("0");
                    carInfo.setCreateTime(DateUtils.getNowDate());
                    carInfoMapper.insertCarInfo(carInfo);
                }
            }
        }

        return flag;
    }

    /**
     * 修改客户信息
     *
     * @param dataCustomerInfo 客户信息
     * @return 结果
     */
    @Override
    @Transactional
    public int updateDataCustomerInfo(DataCustomerInfo dataCustomerInfo, LoginUser userInfo) {

        String oldIdcard = null;
        String newIdcard = null;
        // 根据id查询原来的idcard
        DataCustomerInfo dataCustomerInfoOld = dataCustomerInfoMapper
                .selectDataCustomerInfoById(dataCustomerInfo.getId());
        oldIdcard = dataCustomerInfoOld.getIdCard();
        newIdcard = dataCustomerInfo.getIdCard();
        if (!oldIdcard.equals(newIdcard)) {
            DataCustomerInfo dataCustomer = dataCustomerInfoMapper
                    .selectDataCustomerInfoByIdCard(newIdcard);
            if (dataCustomer != null) {
                throw new CustomException("当前修改的证件号码已存在!!");
            }
        }
        // 同步插入修改记录表
        this.getClUpMap(dataCustomerInfoOld, dataCustomerInfoOld, userInfo);

        // 若身份证也修改了,则同步修改身份证业务关联表的身份证
        upIdCardByIdCard(oldIdcard, newIdcard);

        int flag = 0;

        // 然后网格城区
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgWgsq())) {
            for (DataWgWgsq dataWgWgsq : dataCustomerInfo.getDataWgWgsq()) {
//					if(oldDataWgWgsq.getIdCard() != null){
//						oldIdcard = oldDataWgWgsq.getIdCard();
//					}
                if (dataWgWgsq.getIdCard() != null) {

                    dataWgWgsq.setIdCard(dataWgWgsq.getIdCard());
                }
                dataWgWgsq.setName(dataCustomerInfo.getName());

                dataWgWgsq.setIdCard(newIdcard);
                dataWgWgsq.setAge(dataCustomerInfo.getAge());
                dataWgWgsq.setPhone(dataCustomerInfo.getPhone());
                dataWgWgsq.setCustomerType(dataCustomerInfo.getCustomerType());

                dataWgWgsq.setHzxm(dataCustomerInfo.getHzxm());
                dataWgWgsq.setHjbh(dataCustomerInfo.getHjbh());
                // 判断是否传入户籍编号与户主姓名，如果不存在，则初始化
                if (StringUtils.isEmpty(dataWgWgsq.getHjbh())) {
                    dataWgWgsq.setHjbh(dataCustomerInfo.getIdCard());
                }
                if (StringUtils.isEmpty(dataWgWgsq.getHzxm())) {
                    dataWgWgsq.setHzxm(dataCustomerInfo.getName());
                }
                dataWgWgsq.setAge(dataCustomerInfo.getAge());

                //若id为空表示新增操作   否则为修改
                if (StringUtils.isEmpty(dataWgWgsq.getId())) {
                    dataWgWgsq.setCreateTime(DateUtils.getNowDate());
                    dataWgWgsq.setCreateUser(userInfo.getSysUser().getUserName());
                    // 先判断社区表中是否已存在该客户 不同小区可以重复
                    List<DataWgWgsq> wgsq = dataWgWgsqMapper.selectDataWgWgsq(dataWgWgsq);
                    if (!ListUtil.isNullOrEmpty(wgsq)) {
                        logger.info("当前小区已存在该客户，身份证号码={}", dataCustomerInfo.getIdCard());
                    } else {
                        // 插入社区表
                        flag = dataWgWgsqMapper.insertDataWgWgsq(dataWgWgsq);
                    }
                } else {
                    dataWgWgsq.setUpdateTime(DateUtils.getNowDate());
                    dataWgWgsq.setUpdateBy(userInfo.getSysUser().getUserName());
                    // 获取未修改之前网格商户的数据
                    DataWgWgsq oldDataWgWgsq = dataWgWgsqMapper.selectDataWgWgsqById(dataWgWgsq.getId());
                    flag = dataWgWgsqMapper.updateDataWgWgsq(dataWgWgsq);
                    // 同步插入修改记录表
                    this.getSqUpMap(dataWgWgsq, oldDataWgWgsq, userInfo);
                }
            }
        }
        // 然后村居
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgWgcj())) {
            for (DataWgWgcj dataWgWgcj : dataCustomerInfo.getDataWgWgcj()) {
                // 获取未修改之前的网格村居信息
//				if(oldDataWgWgcj.getIdCard() != null){
//					oldIdcard = oldDataWgWgcj.getIdCard();
//				}
                if (dataWgWgcj.getIdCard() != null) {
                    newIdcard = dataWgWgcj.getIdCard();
                }

                dataWgWgcj.setIdCard(newIdcard);
                dataWgWgcj.setPhone(dataCustomerInfo.getPhone());
                if (dataCustomerInfo.getHjbh() == null) {
                    dataCustomerInfo.setHjbh(newIdcard);
                }
                dataWgWgcj.setHjbh(dataCustomerInfo.getHjbh());
                dataWgWgcj.setHzxm(dataCustomerInfo.getHzxm());
                dataWgWgcj.setName(dataCustomerInfo.getName());
                dataWgWgcj.setCustomerType(dataCustomerInfo.getCustomerType());
                dataWgWgcj.setAge(dataCustomerInfo.getAge());


                //若id为空表示新增操作   否则为修改
                if (StringUtils.isEmpty(dataWgWgcj.getId())) {

                    DataWgWgcj dataWgWgcjs = new DataWgWgcj();
                    dataWgWgcjs.setIdCard(dataCustomerInfo.getIdCard());
                    List<DataWgWgcj> dataWgWgcjList = dataWgWgcjMapper.selectDataWgWgcjList(dataWgWgcjs);
                    if (ListUtil.isNullOrEmpty(dataWgWgcjList)) {
                        //判断网格村居是否上传居住地址 如果不存在，则初始化
                        if (StringUtils.isEmpty(dataWgWgcj.getAddress())) {
                            dataWgWgcj.setAddress(dataCustomerInfo.getAddress());
                        }
                        // 判断是否传入户籍编号与户主姓名，如果不存在，则初始化
                        if (StringUtils.isEmpty(dataWgWgcj.getHjbh())) {
                            dataWgWgcj.setHjbh(dataCustomerInfo.getIdCard());
                        }
                        if (StringUtils.isEmpty(dataWgWgcj.getHzxm())) {
                            dataWgWgcj.setHzxm(dataCustomerInfo.getName());
                        }
                        dataWgWgcj.setCreateTime(DateUtils.getNowDate());
                        dataWgWgcj.setCreateUser(dataCustomerInfo.getUserId());
                        flag = dataWgWgcjMapper.insertDataWgWgcj(dataWgWgcj);
                    }
                } else {
                    dataWgWgcj.setUpdateBy(userInfo.getSysUser().getUserName());
                    dataWgWgcj.setUpdateTime(DateUtils.getNowDate());
                    // 获取未修改之前的网格村居信息
                    DataWgWgcj oldDataWgWgcj = dataWgWgcjMapper.selectDataWgWgcjById(dataWgWgcj.getId());
                    flag = dataWgWgcjMapper.updateDataWgWgcj(dataWgWgcj);
                    this.getCjUpMap(dataWgWgcj, oldDataWgWgcj, userInfo);
                }
            }
        }
        // 然后商户
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataGtgsh())) {
            for (DataGtgsh dataGtgsh : dataCustomerInfo.getDataGtgsh()) {
                if (StringUtils.isEmpty(dataGtgsh.getIdCard())) {
                    dataGtgsh.setIdCard(dataCustomerInfo.getIdCard());
                }

                //判断商户是否上传居住地址 如果不存在，则初始化
                if (StringUtils.isEmpty(dataGtgsh.getAddress())) {
                    dataGtgsh.setAddress(dataGtgsh.getJydz());
                }

                dataGtgsh.setPhone(dataCustomerInfo.getPhone());
                dataGtgsh.setOrgId(dataCustomerInfo.getOrgId());
                dataGtgsh.setUserId(dataCustomerInfo.getUserId());

                if (StringUtils.isEmpty(dataGtgsh.getZjhm())) {
                    dataGtgsh.setZjhm(dataCustomerInfo.getIdCard());
                }

                //若id为空表示新增操作   否则为修改
                if (StringUtils.isEmpty(dataGtgsh.getId())) {
                    DataGtgsh dataGtgshs = dataGtgshMapper.selectDataGtgshByIdCard(dataCustomerInfo.getIdCard(), dataGtgsh.getSssjsq(), dataGtgsh.getSssq());
                    if (dataGtgshs == null) {
                        dataGtgsh.setId(GetOnlyId.getOnlyId());
                        dataGtgsh.setCreateTime(DateUtils.getNowDate());
                        dataGtgsh.setCreateUser(dataCustomerInfo.getUserId());
                        //更新存量表中  是否个体工商户 0否1是
                        dataCustomerInfo.setIfGtgsh("1");
                        dataGtgsh.setIdCard(dataCustomerInfo.getId());
                        // 插入个体工商户表
                        flag = dataGtgshMapper.insertDataGtgsh(dataGtgsh);
                    }
                } else {
                    dataGtgsh.setUpdateTime(DateUtils.getNowDate());
                    dataGtgsh.setUpdateUser(userInfo.getSysUser().getUserName());
                    DataGtgsh oldDataGtgsh = dataGtgshMapper.selectDataGtgshById(dataGtgsh.getId());
                    // 同步插入修改记录表
                    this.addUpdateRecord(oldDataGtgsh, dataGtgsh, userInfo);
                    if ("".equals(dataGtgsh.getBusinessLicense()) || " ".equals(dataGtgsh.getBusinessLicense())) {
                        dataGtgsh.setBusinessLicense(null);
                    }
                    if ("".equals(dataGtgsh.getHeadPhoto()) || " ".equals(dataGtgsh.getHeadPhoto())) {
                        dataGtgsh.setHeadPhoto(null);
                    }
                    flag = dataGtgshMapper.updateDataGtgsh(dataGtgsh);
                }
            }
        }
        // 然后专业市场
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getDataWgZyscKh())) {
            for (DataWgZyscKh dataWgZyscKh : dataCustomerInfo.getDataWgZyscKh()) {
                DataWgZyscKh oldDataWgZyscKh = dataWgZyscKhMapper.selectDataWgZyscKhById(dataWgZyscKh.getId());
                dataWgZyscKh.setPhone(dataCustomerInfo.getPhone());
                dataWgZyscKh.setIdCard(dataCustomerInfo.getIdCard());
                dataWgZyscKh.setName(dataCustomerInfo.getName());

                //若id为空表示新增操作  否则为修改
                if (StringUtils.isEmpty(dataWgZyscKh.getId())) {
                    dataWgZyscKh.setManagerId(dataCustomerInfo.getUserId());
                    dataWgZyscKh.setOrgId(dataCustomerInfo.getOrgId());
                    dataWgZyscKh.setCreateUser(dataCustomerInfo.getUserId());
                    dataWgZyscKh.setCreateTime(DateUtils.getNowDate());
                    if (StringUtils.isEmpty(dataWgZyscKh.getZhenshiJingdu()) || StringUtils.isEmpty(dataWgZyscKh.getZhenshiWeidu())) {
                        throw new CustomException("专业市场定位地址为空,请重新定位!!");
                    }

                    //判断商户是否上传居住地址 如果不存在，则初始化
                    if (StringUtils.isEmpty(dataWgZyscKh.getDwAddress())) {
                        dataWgZyscKh.setDwAddress(dataCustomerInfo.getAddress());
                    }

                    flag = dataWgZyscKhMapper.insertDataWgZyscKh(dataWgZyscKh);
                } else {
                    // 同步插入修改记录表
                    //	this.addUpdateRecord(oldDataGtgsh, dataGtgsh, userInfo);
                    dataWgZyscKh.setUpdateTime(DateUtils.getNowDate());
                    flag = dataWgZyscKhMapper.updateDataWgZyscKh(dataWgZyscKh);
                }

            }
        }

        /**
         * 修改群体信息
         * 此时多个标签信息直接会被转为字符串存入数据库，只会产生一条数据，直接更新即可
         */
        DataCustomerGroupRelation relationCondition = dataCustomerInfo.getGroupLabel();
        if (relationCondition != null) {
            relationCondition.setStatus("1");// 1表示有效
            relationCondition.setIdCard(dataCustomerInfo.getIdCard());
            relationCondition.setUserId(dataCustomerInfo.getUserId());
            relationCondition.setOrgId(dataCustomerInfo.getOrgId());

            DataCustomerGroupRelation groupRelation =
                    dataCustomerGroupRelationMapper.selectDataCustomerGroupRelationById(dataCustomerInfo.getIdCard());
            if (groupRelation != null) {
                relationCondition.setUpdateTime(DateUtils.getNowDate());
                flag = dataCustomerGroupRelationMapper.updateDataCustomerGroupRelation(relationCondition);
            } else {
                relationCondition.setCreateTime(DateUtils.getNowDate());
                flag = dataCustomerGroupRelationMapper.insertDataCustomerGroupRelation(relationCondition);
            }
        }

        //先逻辑删除车辆信息
        CarInfo cars = new CarInfo();
        cars.setIdCard(dataCustomerInfo.getIdCard());
        cars.setStatus("1");
        cars.setUpdateTime(DateUtils.getNowDate());
        carInfoMapper.updateCarInfoByIdCard(cars);
        //判断是否新增信息的同时添加了车辆信息
        if (!ListUtil.isNullOrEmpty(dataCustomerInfo.getCarInfoList())) {
            for (CarInfo carInfo : dataCustomerInfo.getCarInfoList()) {
                //id 为空说明是新增的  不为空则修改
                if (StringUtils.isEmpty(carInfo.getId())) {
                    carInfo.setId(GetOnlyId.getOnlyId());
                    carInfo.setIdCard(dataCustomerInfo.getIdCard());
                    carInfo.setName(dataCustomerInfo.getName());
                    carInfo.setStatus("0");
                    carInfo.setCreateTime(DateUtils.getNowDate());
                    carInfoMapper.insertCarInfo(carInfo);
                } else {
                    carInfo.setUpdateTime(DateUtils.getNowDate());
                    carInfo.setStatus("0");
                    carInfoMapper.updateCarInfo(carInfo);
                }
            }
        }
        // 先更新存量客户
        dataCustomerInfo.setUpdateTime(DateUtils.getNowDate());
        dataCustomerInfo.setUpdateUser(dataCustomerInfo.getUserId());
        flag = dataCustomerInfoMapper.updateDataCustomerInfo(dataCustomerInfo);
        return flag;
    }

    /**
     * 对比传递的身份证与数据库中对比，如果不一致，则更新身份证 如果一致，则不更新身份证
     *
     * @param oldIdCard 未修改的IdCard
     * @param newIdCard 本次传过来的IdCard
     * @return
     */
    private void upIdCardByIdCard(String oldIdCard, String newIdCard) {
        try {
            if (newIdCard == null || "".equals(newIdCard)) {
                return;
            }
            if (oldIdCard == null || "".equals(oldIdCard)) {
                return;
            }
            if (!newIdCard.equals(oldIdCard)) {

                /**
                 * 身份证变更之后，修改家庭成员表IdCard DATA_WG_JTCY 修改家庭成员表
                 */
//                DataWgJtcy dataWgJtcy = new DataWgJtcy();
//                dataWgJtcy.setIdCard(oldIdCard);
//                List<DataWgJtcy> dataWgJtcyList = dataWgJtcyMapper.selectDataWgJtcyList(dataWgJtcy);
//                for (DataWgJtcy wgJtcy : dataWgJtcyList) {
//                    wgJtcy.setIdCard(newIdCard);
//                    dataWgJtcyMapper.updateDataWgJtcy(wgJtcy);
//                }

                /**
                 * 身份证变更之后，修改营销任务相关表数据 DATA_USER_TASK_RELATION 修改营销任务和客户关系表
                 */
                DataUserTaskRelation dataUserTaskRelation = new DataUserTaskRelation();
                dataUserTaskRelation.setIdCard(oldIdCard);
                List<DataUserTaskRelation> doList = dataUserTaskRelationMapper
                        .selectDataUserTaskRelationList(dataUserTaskRelation);
                if (!ListUtil.isNullOrEmpty(doList)) {
                    dataUserTaskRelationMapper.upUserTaskIdCardByIdCard(oldIdCard, newIdCard);
                }

                /**
                 * 身份证变更之后，修改营销任务执行记录表数据 DATA_TASK_EX_RECORD 修改营销任务执行记录表
                 */
                DataTaskExRecord dataTaskExRecord = new DataTaskExRecord();
                dataTaskExRecord.setIdCard(oldIdCard);
                List<DataTaskExRecord> taskExRecordList = dataTaskExRecordMapper
                        .selectDataTaskExRecordList(dataTaskExRecord);
                if (!ListUtil.isNullOrEmpty(taskExRecordList)) {
                    dataTaskExRecordMapper.updateDataTaskExRecordByIdCard(oldIdCard, newIdCard);
                }

                /**
                 * 身份证变更之后，修改营销任务执行记录退回表IdCard DATA_TASK_EX_RECORD_BACK 修改营销任务执行记录退回表
                 */
                DataTaskExRecordBack dataTaskExRecordBack = new DataTaskExRecordBack();
                dataTaskExRecordBack.setIdCard(oldIdCard);
                List<DataTaskExRecordBack> TaskExRecordBackList = dataTaskExRecordBackMapper
                        .selectDataTaskExRecordBackList(dataTaskExRecordBack);
                if (!ListUtil.isNullOrEmpty(TaskExRecordBackList)) {
                    dataTaskExRecordBackMapper.upTaskExRecordBackIdCardByIdCard(oldIdCard, newIdCard);
                }

                /**
                 * 身份证变更之后，修改家庭成员表IdCard DATA_WG_JTCY 修改h家庭成员表
                 */
                DataWgJtcy WgJtcy = new DataWgJtcy();
                WgJtcy.setIdCard(oldIdCard);
                List<DataWgJtcy> WgJtcyList = dataWgJtcyMapper.selectDataWgJtcyList(WgJtcy);
                if (!ListUtil.isNullOrEmpty(WgJtcyList)) {
                    dataWgJtcyMapper.upJtcyIdCardByIdCard(oldIdCard, newIdCard);
                }

                /**
                 * 身份证变更之后，修改群体标签表IdCard DATA_CUSTOMER_GROUP_RELATION 修改群体标签表
                 */
                DataCustomerGroupRelation dataCustomerGroupRelation = new DataCustomerGroupRelation();
                dataCustomerGroupRelation.setIdCard(oldIdCard);
                List<DataCustomerGroupRelation> customerGroupRelationList = dataCustomerGroupRelationMapper
                        .selectDataCustomerGroupRelationList(dataCustomerGroupRelation);
                if (!ListUtil.isNullOrEmpty(customerGroupRelationList)) {
                    dataCustomerGroupRelationMapper.updateIDcard(oldIdCard, newIdCard);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("同步修改客户相关表证件号异常:" + e.getMessage());
        }
    }

    @Override
    public List<Map<String, Object>> KhLevelChange(DataCustomerInfoVO dataCustomerInfoVO, LoginUser userInfo) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> map = new HashMap<String, Object>();
        list = dataCustomerInfoMapper.khLevelChange(dataCustomerInfoVO.getIdCard());
        List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
        if (list.size() > 0) {
            map = list.get(0);
            for (int i = 1; i < list.size(); i++) {
                if (!list.get(i).get("level").equals(map.get("level"))) {
                    Map<String, Object> maps = new HashMap<String, Object>();
                    maps.put("idCard", list.get(i).get("idCard"));
                    maps.put("newLevel", list.get(i).get("level"));
                    maps.put("name", list.get(i).get("name"));
                    maps.put("newSjrq", list.get(i).get("sjrq"));
                    maps.put("oldSjrq", map.get("sjrq"));
                    maps.put("newLevel", list.get(i).get("level"));
                    maps.put("oldLevel", map.get("level"));
                    maps.put("djc", Integer.valueOf(list.get(i).get("level").toString()) - Integer.valueOf(map.get("level").toString()));
                    lists.add(maps);
                }
                map = list.get(i);
            }
        }

        return lists;
    }


    private void getClUpMap(DataCustomerInfo newVo, DataCustomerInfo oldVo, LoginUser userDo) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> maps = new HashMap<String, Object>();
        String record = GetOnlyId.getOnlyId();
        maps.put("idCard", newVo.getIdCard());
        maps.put("name", newVo.getName());
        maps.put("userId", userDo.getSysUser().getUserName());
        maps.put("status", "1");
        // 1存量2商户3村居4专业市场5专业市场
        maps.put("type", "1");
        maps.put("record", record);
        if (!StringUtils.isEmpty(newVo.getIdCard())) {
            if (!newVo.getIdCard().equals(oldVo.getIdCard())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ID_CARD(身份证号)");
                map.put("oldValue", oldVo.getIdCard());
                map.put("newValue", newVo.getIdCard());
                list.add(map);
                // 若修改身份证 则将本次记录的身份证都改为新身份证
                maps.put("idCard", oldVo.getIdCard());
                // 将变更记录表中的身份证改成最新的
                dataCustomerRecordMapper.upRecoro(oldVo.getIdCard(), newVo.getIdCard());
            }
        }
        if (!StringUtils.isEmpty(newVo.getName())) {
            if (!newVo.getName().equals(oldVo.getName())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "NAME(姓名),");
                map.put("oldValue", oldVo.getName());
                map.put("newValue", newVo.getName());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getSpouseName())) {
            if (!newVo.getSpouseName().equals(oldVo.getSpouseName())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "SPOUSE_NAME(配偶姓名)");
                map.put("oldValue", oldVo.getSpouseName());
                map.put("newValue", newVo.getSpouseName());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getPhone())) {
            if (!newVo.getPhone().equals(oldVo.getPhone())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "PHONE(联系电话)");
                map.put("oldValue", oldVo.getPhone());
                map.put("newValue", newVo.getPhone());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getAddress())) {
            if (!newVo.getAddress().equals(oldVo.getAddress())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ADDRESS(地址)");
                map.put("oldValue", oldVo.getAddress());
                map.put("newValue", newVo.getAddress());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getMaritalStatus())) {
            if (!newVo.getMaritalStatus().equals(oldVo.getMaritalStatus())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "MARITAL_STATUS(婚姻情况)");
                map.put("oldValue", oldVo.getMaritalStatus());
                map.put("newValue", newVo.getMaritalStatus());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getCustomerType())) {
            if (!newVo.getCustomerType().equals(oldVo.getCustomerType())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CUSTOMER_TYPE(客户类型)");
                map.put("oldValue", oldVo.getCustomerType());
                map.put("newValue", newVo.getCustomerType());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getCustomerLevel())) {
            if (!newVo.getCustomerLevel().equals(oldVo.getCustomerLevel())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CUSTOMER_LEVEL(客户等级：0普通客户 1白银客户 2黄金客户 3铂金客户 4钻石客户)");
                map.put("oldValue", oldVo.getCustomerLevel());
                map.put("newValue", newVo.getCustomerLevel());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getPoints())) {
            if (!newVo.getPoints().equals(oldVo.getPoints())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "POINTS(积分)");
                map.put("oldValue", oldVo.getPoints());
                map.put("newValue", newVo.getPoints());
                list.add(map);
            }
        }

        if (!StringUtils.isEmpty(newVo.getStatus())) {
            if (!newVo.getStatus().equals(oldVo.getStatus())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "STATUS(状态(1有效，0无效))");
                map.put("oldValue", oldVo.getStatus());
                map.put("newValue", newVo.getStatus());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getRemark())) {
            if (!newVo.getRemark().equals(oldVo.getRemark())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "REMARK(备注)");
                map.put("oldValue", oldVo.getRemark());
                map.put("newValue", newVo.getRemark());
                list.add(map);
            }
        }

        if (!StringUtils.isEmpty(newVo.getIfFenpei())) {
            if (!newVo.getIfFenpei().equals(oldVo.getIfFenpei())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "IF_FENPEI(是否分配客户经理（1是，0未分配）)");
                map.put("oldValue", oldVo.getIfFenpei());
                map.put("newValue", newVo.getIfFenpei());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getIsPublic())) {
            if (!newVo.getIsPublic().equals(oldVo.getIsPublic())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "IS_PUBLIC(是否是公共池客户  0否 1是)");
                map.put("oldValue", oldVo.getIsPublic());
                map.put("newValue", newVo.getIsPublic());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getCustomerLevelZh())) {
            if (!newVo.getCustomerLevelZh().equals(oldVo.getCustomerLevelZh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CUSTOMER_LEVEL_ZH(客户等级：0普通客户 1白银客户 2黄金客户 3铂金客户 4钻石客户)");
                map.put("oldValue", oldVo.getCustomerLevelZh());
                map.put("newValue", newVo.getCustomerLevelZh());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getOrgId())) {
            if (!newVo.getOrgId().equals(oldVo.getOrgId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ORG_ID(所属机构ID)");
                map.put("oldValue", oldVo.getOrgId());
                map.put("newValue", newVo.getOrgId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getManagerId())) {
            if (!newVo.getManagerId().equals(oldVo.getManagerId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "MANAGER_ID(信贷系统ID)");
                map.put("oldValue", oldVo.getManagerId());
                map.put("newValue", newVo.getManagerId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getUserId())) {
            if (!newVo.getUserId().equals(oldVo.getUserId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "USER_ID(工号)");
                map.put("oldValue", oldVo.getUserId());
                map.put("newValue", newVo.getUserId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(newVo.getIsExpand())) {
            if (!newVo.getIsExpand().equals(oldVo.getIsExpand())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "IS_EXPAND(扩展客户)");
                map.put("oldValue", oldVo.getIsExpand());
                map.put("newValue", newVo.getIsExpand());
                list.add(map);
            }
        }

        if (!StringUtils.isEmpty(list)) {
            for (Map<String, Object> map : list) {
                System.err.println(map.toString());
                dataCustomerRecordMapper.insertCustRecord(map);// DATA_CUSTOMER_RECORD
            }
        }
    }

    private void getCjUpMap(DataWgWgcj vo, DataWgWgcj cjVo, LoginUser userDo) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> maps = new HashMap<String, Object>();
        String record = GetOnlyId.getOnlyId();
        maps.put("idCard", vo.getIdCard());
        maps.put("name", vo.getName());
        maps.put("userId", userDo.getSysUser().getUserName());
        maps.put("status", "1");
        // 2商户3村居4专业市场5专业市场
        maps.put("type", "3");
        maps.put("record", record);
        if (!StringUtils.isEmpty(vo.getIdCard())) {
            if (!vo.getIdCard().equals(cjVo.getIdCard())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ID_CARD(身份证)");
                map.put("oldValue", cjVo.getIdCard());
                map.put("newValue", vo.getIdCard());
                list.add(map);
                // 若修改身份证 则将本次记录的身份证都改为新身份证
                maps.put("idCard", cjVo.getIdCard());
                // 将变更记录表中的身份证改成最新的
                dataCustomerRecordMapper.upRecoro(cjVo.getIdCard(), vo.getIdCard());
            }
        }
        if (!StringUtils.isEmpty(vo.getAddress())) {
            if (!vo.getAddress().equals(cjVo.getAddress())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ADDRESS(村居地址)");
                map.put("oldValue", cjVo.getAddress());
                map.put("newValue", vo.getAddress());
                list.add(map);
            }
        }

        if (!(vo.getAge() + "").equals(cjVo.getAge() + "")) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.putAll(maps);
            map.put("id", GetOnlyId.getOnlyId());
            map.put("attribute", "AGE(年龄)");
            map.put("oldValue", String.valueOf(cjVo.getAge()));
            map.put("newValue", String.valueOf(vo.getAge()));
            list.add(map);
        }

        if (!StringUtils.isEmpty(vo.getBadHabits())) {
            if (!vo.getBadHabits().equals(cjVo.getBadHabits())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "BAD_HABITS(不良嗜好 0无  1有)");
                map.put("oldValue", cjVo.getBadHabits());
                map.put("newValue", vo.getBadHabits());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getBlack())) {
            if (!vo.getBlack().equals(cjVo.getBlack())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "BLACK(本行黑名单 0否 1是)");
                map.put("oldValue", cjVo.getBlack());
                map.put("newValue", vo.getBlack());
                list.add(map);
            }
        }
        if (!(vo.getBreedLand() + "").equals(cjVo.getBreedLand() + "")) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.putAll(maps);
            map.put("id", GetOnlyId.getOnlyId());
            map.put("attribute", "BREED_LAND(养殖土地(亩))");
            map.put("oldValue", cjVo.getBreedLand());
            map.put("newValue", vo.getBreedLand());
            list.add(map);
        }
        if (!StringUtils.isEmpty(vo.getCar())) {
            if (!vo.getCar().equals(cjVo.getCar())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CAR(动产（1私家车、2大型农机、3无）)");
                map.put("oldValue", cjVo.getCar());
                map.put("newValue", vo.getCar());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getCustomerType())) {
            if (!vo.getCustomerType().equals(cjVo.getCustomerType())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CUSTOMER_TYPE(客户类型 0 普通客户 1潜在客户 2重点客户)");
                map.put("oldValue", cjVo.getCustomerType());
                map.put("newValue", vo.getCustomerType());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getGroup())) {
            if (!vo.getGroup().equals(cjVo.getGroup())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "GROUP(组)");
                map.put("oldValue", cjVo.getGroup());
                map.put("newValue", vo.getGroup());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getHealth())) {
            if (!vo.getHealth().equals(cjVo.getHealth())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HEALTH(健康状况 1健康、2一般、3重大疾病)");
                map.put("oldValue", cjVo.getHealth());
                map.put("newValue", vo.getHealth());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getHjbh())) {
            if (!vo.getHjbh().equals(cjVo.getHjbh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HJBH(户籍编号)");
                map.put("oldValue", cjVo.getHjbh());
                map.put("newValue", vo.getHjbh());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getHjbh())) {
            if (!vo.getHjbh().equals(cjVo.getHjbh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HOURSE(房产 1农村平房、2农村楼房、3县级以上商品房)");
                map.put("oldValue", cjVo.getHjbh());
                map.put("newValue", vo.getHourse());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getHzxm())) {
            if (!vo.getHzxm().equals(cjVo.getHzxm())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HZXM(户主姓名)");
                map.put("oldValue", cjVo.getHzxm());
                map.put("newValue", vo.getHzxm());
                list.add(map);
            }
        }

        if (!(vo.getLabour() + "").equals(cjVo.getLabour() + "")) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.putAll(maps);
            map.put("id", GetOnlyId.getOnlyId());
            map.put("attribute", "LABOUR(家庭劳动力)");
            map.put("oldValue", cjVo.getLabour());
            map.put("newValue", vo.getLabour());
            list.add(map);
        }
        if (!StringUtils.isEmpty(vo.getLand())) {
            if (!vo.getLand().equals(cjVo.getLand() + "")) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LAND(土地(亩))");
                map.put("oldValue", cjVo.getLand());
                map.put("newValue", vo.getLand());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLuojiJingdu())) {
            if (!vo.getLuojiJingdu().equals(cjVo.getLuojiJingdu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LUOJI_JINGDU(逻辑经度)");
                map.put("oldValue", cjVo.getLuojiJingdu());
                map.put("newValue", vo.getLuojiJingdu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLuojiWeidu())) {
            if (!vo.getLuojiWeidu().equals(cjVo.getLuojiWeidu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LUOJI_WEIDU(逻辑纬度)");
                map.put("oldValue", cjVo.getLuojiWeidu());
                map.put("newValue", vo.getLuojiWeidu());
                list.add(map);
            }
        }

        if (!StringUtils.isEmpty(vo.getManagerId())) {
            if (!vo.getManagerId().equals(cjVo.getManagerId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "MANAGER_ID(管户经理)");
                map.put("oldValue", cjVo.getManagerId());
                map.put("newValue", vo.getManagerId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getName())) {
            if (!vo.getName().equals(cjVo.getName())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "NAME(姓名)");
                map.put("oldValue", cjVo.getName());
                map.put("newValue", vo.getName());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getOrgId())) {
            if (!vo.getOrgId().equals(cjVo.getOrgId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ORG_ID(管户机构)");
                map.put("oldValue", cjVo.getOrgId());
                map.put("newValue", vo.getOrgId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getPhone())) {
            if (!vo.getPhone().equals(cjVo.getPhone())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "PHONE(联系电话)");
                map.put("oldValue", cjVo.getPhone());
                map.put("newValue", vo.getPhone());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getPkh())) {
            if (!vo.getPkh().equals(cjVo.getPkh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "PKH(贫困户  0否  1是)");
                map.put("oldValue", cjVo.getPkh());
                map.put("newValue", vo.getPkh());
                list.add(map);
            }
        }
        if (!(vo.getPlantLand() + "").equals(cjVo.getPlantLand() + "")) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.putAll(maps);
            map.put("id", GetOnlyId.getOnlyId());
            map.put("attribute", "PLANT_LAND(种植土地(亩))");
            map.put("oldValue", cjVo.getPlantLand());
            map.put("newValue", vo.getPlantLand());
            list.add(map);
        }
        if (!StringUtils.isEmpty(vo.getRemark())) {
            if (!vo.getRemark().equals(cjVo.getRemark())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "REMARK(备注)");
                map.put("oldValue", cjVo.getRemark());
                map.put("newValue", vo.getRemark());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getSex())) {
            if (!vo.getSex().equals(cjVo.getSex())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "SEX(性别 0女 1男)");
                map.put("oldValue", cjVo.getSex());
                map.put("newValue", vo.getSex());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getSxed())) {
            if (!vo.getSxed().equals(cjVo.getSxed())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "SXED(整村授信家庭额度)");
                map.put("oldValue", cjVo.getSxed());
                map.put("newValue", vo.getSxed());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getTown())) {
            if (!vo.getTown().equals(cjVo.getTown())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "TOWN(镇)");
                map.put("oldValue", cjVo.getTown());
                map.put("newValue", vo.getTown());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getVillage())) {
            if (!vo.getVillage().equals(cjVo.getVillage())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "VILLAGE(村)");
                map.put("oldValue", cjVo.getVillage());
                map.put("newValue", vo.getVillage());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getWorkAddress())) {
            if (!vo.getWorkAddress().equals(cjVo.getWorkAddress())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "WORK_ADDRESS(务工地点)");
                map.put("oldValue", cjVo.getWorkAddress());
                map.put("newValue", vo.getWorkAddress());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getWorkType())) {
            if (!vo.getWorkType().equals(cjVo.getWorkType())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "WORK_TYPE(是否外地务工 0否 1是 (1.种养殖大户2.外出务工3.务农4.个体工商户))");
                map.put("oldValue", cjVo.getWorkType());
                map.put("newValue", vo.getWorkType());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getYhzgx())) {
            if (!vo.getYhzgx().equals(cjVo.getYhzgx())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "YHZGX(与户主关系 1户主 2配偶 3.父母 4子女  5其它)");
                map.put("oldValue", cjVo.getYhzgx());
                map.put("newValue", vo.getYhzgx());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getZhenshiJingdu())) {
            if (!vo.getZhenshiJingdu().equals(cjVo.getZhenshiJingdu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ZHENSHI_JINGDU(真实经度)");
                map.put("oldValue", cjVo.getZhenshiJingdu());
                map.put("newValue", vo.getZhenshiJingdu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getZhenshiWeidu())) {
            if (!vo.getZhenshiWeidu().equals(cjVo.getZhenshiWeidu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ZHENSHI_WEIDU(真实纬度)");
                map.put("oldValue", cjVo.getZhenshiWeidu());
                map.put("newValue", vo.getZhenshiWeidu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(list)) {
            for (Map<String, Object> map : list) {
                System.err.println(map.toString());
                dataCustomerRecordMapper.insertCustRecord(map);// DATA_CUSTOMER_RECORD
            }
        }
    }

    private void getSqUpMap(DataWgWgsq vo, DataWgWgsq sqVo, LoginUser userDo) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> maps = new HashMap<String, Object>();
        String record = GetOnlyId.getOnlyId();
        maps.put("idCard", vo.getIdCard());
        maps.put("name", vo.getName());
        maps.put("userId", userDo.getSysUser().getUserName());
        maps.put("status", "1");
        maps.put("record", record);
        // 2商户3村居4专业市场5专业市场
        maps.put("type", "3");
        if (!StringUtils.isEmpty(vo.getIdCard())) {
            if (!vo.getIdCard().equals(sqVo.getIdCard())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ID_CARD");
                map.put("oldValue", sqVo.getIdCard());
                map.put("newValue", vo.getIdCard());
                list.add(map);
                // 若修改身份证 则将本次记录的身份证都改为新身份证
                maps.put("idCard", sqVo.getIdCard());
                // 将变更记录表中的身份证改成最新的
                dataCustomerRecordMapper.upRecoro(sqVo.getIdCard(), vo.getIdCard());
            }
        }
        if (!StringUtils.isEmpty(vo.getHjbh())) {
            if (!vo.getHjbh().equals(sqVo.getHjbh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HJBH");
                map.put("oldValue", sqVo.getHjbh());
                map.put("newValue", vo.getHjbh());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getHzxm())) {
            if (!vo.getHzxm().equals(sqVo.getHzxm())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "HZXM");
                map.put("oldValue", sqVo.getHzxm());
                map.put("newValue", vo.getHzxm());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getName())) {
            if (!vo.getName().equals(sqVo.getName())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "NAME");
                map.put("oldValue", sqVo.getName());
                map.put("newValue", vo.getName());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getSex())) {
            if (!vo.getSex().equals(sqVo.getSex())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "SEX");
                map.put("oldValue", sqVo.getSex());
                map.put("newValue", vo.getSex());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getYhzgx())) {
            if (!vo.getYhzgx().equals(sqVo.getYhzgx())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "YHZGX");
                map.put("oldValue", sqVo.getYhzgx());
                map.put("newValue", vo.getYhzgx());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getSssq())) {
            if (!vo.getSssq().equals(sqVo.getSssq())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "SSSQ");
                map.put("oldValue", sqVo.getSssq());
                map.put("newValue", vo.getSssq());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLongLive())) {
            if (!vo.getLongLive().equals(sqVo.getLongLive())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LONG_LIVE");
                map.put("oldValue", sqVo.getLongLive());
                map.put("newValue", vo.getLongLive());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getAddress())) {
            if (!vo.getAddress().equals(sqVo.getAddress())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ADDRESS");
                map.put("oldValue", sqVo.getAddress());
                map.put("newValue", vo.getAddress());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getJzAddress())) {
            if (!vo.getJzAddress().equals(sqVo.getJzAddress())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "JZ_ADDRESS");
                map.put("oldValue", sqVo.getJzAddress());
                map.put("newValue", vo.getJzAddress());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLabour())) {
            if (!vo.getLabour().equals(sqVo.getLabour())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LABOUR");
                map.put("oldValue", sqVo.getLabour());
                map.put("newValue", vo.getLabour());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getJoinActive())) {
            if (!vo.getJoinActive().equals(sqVo.getJoinActive())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "JOIN_ACTIVE");
                map.put("oldValue", sqVo.getJoinActive());
                map.put("newValue", vo.getJoinActive());
                list.add(map);
            }
        }

        if (!StringUtils.isEmpty(vo.getCustomerType())) {
            if (!vo.getCustomerType().equals(sqVo.getCustomerType())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "CUSTOMER_TYPE");
                map.put("oldValue", sqVo.getCustomerType());
                map.put("newValue", vo.getCustomerType());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getPkh())) {
            if (!vo.getPkh().equals(sqVo.getPkh())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "PKH");
                map.put("oldValue", sqVo.getPkh());
                map.put("newValue", vo.getPkh());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getBlack())) {
            if (!vo.getBlack().equals(sqVo.getBlack())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "BLACK");
                map.put("oldValue", sqVo.getBlack());
                map.put("newValue", vo.getBlack());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getOrgId())) {
            if (!vo.getOrgId().equals(sqVo.getOrgId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ORG_ID");
                map.put("oldValue", sqVo.getOrgId());
                map.put("newValue", vo.getOrgId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getManagerId())) {
            if (!vo.getManagerId().equals(sqVo.getManagerId())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "MANAGER_ID");
                map.put("oldValue", sqVo.getManagerId());
                map.put("newValue", vo.getManagerId());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLuojiJingdu())) {
            if (!vo.getLuojiJingdu().equals(sqVo.getLuojiJingdu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LUOJI_JINGDU");
                map.put("oldValue", sqVo.getLuojiJingdu());
                map.put("newValue", vo.getLuojiJingdu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getLuojiWeidu())) {
            if (!vo.getLuojiWeidu().equals(sqVo.getLuojiWeidu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "LUOJI_WEIDU");
                map.put("oldValue", sqVo.getLuojiWeidu());
                map.put("newValue", vo.getLuojiWeidu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getZhenshiJingdu())) {
            if (!vo.getZhenshiJingdu().equals(sqVo.getZhenshiJingdu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ZHENSHI_JINGDU");
                map.put("oldValue", sqVo.getZhenshiJingdu());
                map.put("newValue", vo.getZhenshiJingdu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getZhenshiWeidu())) {
            if (!vo.getZhenshiWeidu().equals(sqVo.getZhenshiWeidu())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "ZHENSHI_WEIDU");
                map.put("oldValue", sqVo.getZhenshiWeidu());
                map.put("newValue", vo.getZhenshiWeidu());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getPhone())) {
            if (!vo.getPhone().equals(sqVo.getPhone())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "PHONE");
                map.put("oldValue", sqVo.getPhone());
                map.put("newValue", vo.getPhone());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getRemark())) {
            if (!vo.getRemark().equals(sqVo.getRemark())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "REMARK");
                map.put("oldValue", sqVo.getRemark());
                map.put("newValue", vo.getRemark());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(vo.getIsExpand())) {
            if (!vo.getIsExpand().equals(sqVo.getIsExpand())) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.putAll(maps);
                map.put("id", GetOnlyId.getOnlyId());
                map.put("attribute", "IS_EXPAND");
                map.put("oldValue", sqVo.getIsExpand());
                map.put("newValue", vo.getIsExpand());
                list.add(map);
            }
        }
        if (!StringUtils.isEmpty(list)) {
            for (Map<String, Object> map : list) {
                System.err.println(map.toString());
                dataCustomerRecordMapper.insertCustRecord(map);// DATA_CUSTOMER_RECORD
            }
        }
    }

    private void addUpdateRecord(DataGtgsh old, DataGtgsh gtgsh, LoginUser userDo) {
        List<Map<String, Object>> list = new ArrayList<>();

        String record = GetOnlyId.getOnlyId();
        if (this.checkValueChange(old.getZjhm(), gtgsh.getZjhm())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "证件号码");
            map.put("oldValue", old.getZjhm());
            map.put("newValue", gtgsh.getZjhm());
            map.put("userId", userDo.getSysUser().getUserName());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
            // 当修改证件号码，必须将修改记录表中原来的证件号码更新为新的证件号码
            // 将变更记录表中的身份证改成最新的
            dataCustomerRecordMapper.upRecoro(old.getZjhm(), gtgsh.getZjhm());
            old.setZjhm(gtgsh.getZjhm());
        }
        if (this.checkValueChange(old.getShmt(), gtgsh.getShmt())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "商户门头");
            map.put("oldValue", old.getShmt());
            map.put("newValue", gtgsh.getShmt());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getShzcmc(), gtgsh.getShzcmc())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "商户注册名称");
            map.put("oldValue", old.getShzcmc());
            map.put("newValue", gtgsh.getShzcmc());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getJyfw(), gtgsh.getJyfw())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "经营范围");
            map.put("oldValue", old.getJyfw());
            map.put("newValue", gtgsh.getJyfw());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getJydz(), gtgsh.getJydz())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "经营地址");
            map.put("oldValue", old.getJydz());
            map.put("newValue", gtgsh.getJydz());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getFddbr(), gtgsh.getFddbr())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "法定代表人");
            map.put("oldValue", old.getFddbr());
            map.put("newValue", gtgsh.getFddbr());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getFddbrzjhm(), gtgsh.getFddbrzjhm())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "法定代表人证件号码");
            map.put("oldValue", old.getFddbrzjhm());
            map.put("newValue", gtgsh.getFddbrzjhm());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getSjjyr(), gtgsh.getSjjyr())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "实际经营人");
            map.put("oldValue", old.getSjjyr());
            map.put("newValue", gtgsh.getSjjyr());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getSjjyrzjhm(), gtgsh.getSjjyrzjhm())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "实际经营人证件号码");
            map.put("oldValue", old.getSjjyrzjhm());
            map.put("newValue", gtgsh.getSjjyrzjhm());
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (this.checkValueChange(old.getJyzk(), gtgsh.getJyzk())) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("record", record);
            map.put("type", "2");
            map.put("idCard", gtgsh.getZjhm());
            map.put("attribute", "经营状况");
            map.put("oldValue", "0".equals(old.getJyzk()) ? "不正常" : "正常");
            map.put("newValue", "0".equals(gtgsh.getJyzk()) ? "不正常" : "正常");
            map.put("userId", gtgsh.getUpdateUser());// 从当前客户经理登陆信息中获取
            map.put("id", GetOnlyId.getOnlyId());
            list.add(map);
        }
        if (!StringUtils.isEmpty(list)) {
            for (Map<String, Object> map : list) {
                System.err.println(map.toString());
                dataCustomerRecordMapper.insertCustRecord(map);// DATA_CUSTOMER_RECORD
            }
        }
    }

    private boolean checkValueChange(String oldV, String newV) {
        if (StringUtils.isEmpty(newV)) {
            return false;
        }
        if (StringUtils.isEmpty(oldV) && StringUtils.isEmpty(newV)) {
            // 两个值都为空，表示没有变更，不做记录
            return false;
        } else if (StringUtils.isEmpty(oldV) && !newV.equals(oldV)) {
            // 原来的值为空，且不等于修改后的值
            return true;
        } else if (StringUtils.isEmpty(newV) && !oldV.equals(newV)) {
            // 修改后的值为空，但原来的值不为空
            return true;
        } else {
            return !newV.equals(oldV);
        }
    }

    /**
     * 批量删除客户信息
     *
     * @param ids 需要删除的客户信息ID
     * @return 结果
     */
    @Override
    public int deleteDataCustomerInfoByIds(String[] ids) {
        return dataCustomerInfoMapper.deleteDataCustomerInfoByIds(ids);
    }

    /**
     * 删除客户信息信息
     *
     * @param id 客户信息ID
     * @return 结果
     */
    @Override
    public int deleteDataCustomerInfoById(String id) {
        return dataCustomerInfoMapper.deleteDataCustomerInfoById(id);
    }

    /**
     * 设置头像信息
     *
     * @param idCard
     * @param sex
     * @return
     */
    @Override
    public String getHeadPic(String idCard, String sex) {
        String res = "";

        List<DataCustomerGroup> groupLabel = dataCustomerGroupMapper.listGroupByIdcard(idCard);
        if (ListUtil.isNullOrEmpty(groupLabel)) {
            if ("0".equals(sex)) {
                return "WOMAN";
            } else {
                return "MAN";
            }
        }
        res = groupLabel.get(0).getGroupCode();
        if ("OTHER".equals(res) || "other".equals(res)) {
            if ("0".equals(sex) || "女".equals(sex)) {
                res = "WOMAN";
            } else {
                res = "MAN";
            }
        }
        return res;
    }


    @Override
    public List<ReportywxxLsb> ywxxtjt(ReportywxxLsb ReportywxxLsb) {
        List<ReportywxxLsb> list = new ArrayList<ReportywxxLsb>();
        String fddbrZjhm = null;
        String sjjyrZjhm = null;
        ArrayList<String> idCards = new ArrayList<String>();
        idCards.add(ReportywxxLsb.getIdCard());
        if ("2".equals(ReportywxxLsb.getType()) && StringUtils.isNotEmpty(ReportywxxLsb.getId())) {
            DataGtgsh dataGtgsh = dataGtgshMapper.selectDataGtgshById(ReportywxxLsb.getId());
            fddbrZjhm = dataGtgsh.getFddbrzjhm();
            sjjyrZjhm = dataGtgsh.getSjjyrzjhm();
            if (!StringUtils.isEmpty(fddbrZjhm)) {
                idCards.add(fddbrZjhm);
            }
            if (!StringUtils.isEmpty(sjjyrZjhm)) {
                idCards.add(sjjyrZjhm);
            }
        }
        ReportywxxLsb.setIdCards(idCards);
        /**
         * 获取三年内每个月最后一天
         */
        ArrayList<String> sjrqs = DateUtilss.getEndMonthByYear(1, 0);
        ReportywxxLsb.setSjrqs(sjrqs);
        list = qmcyCustPersonalInfoMapper.ywxxtjt(ReportywxxLsb);
        return list;
    }

    @Override
    public List<DataCustomerInfo> selectDataCustomerInfoListWithNetCard() {
        return dataCustomerInfoMapper.selectDataCustomerInfoListWithNetCard();
    }

    @Override
    public void updateDataCustomerInfoWithNetCard(DataCustomerInfo dataCustomerInfo) {
        dataCustomerInfoMapper.updateDataCustomerInfoWithNetCard(dataCustomerInfo);
    }

    @Override
    public List<DataCustomerInfo> findCustomerInfoList(LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();
        DataCustomerInfo dataCustomerInfo = new DataCustomerInfo();
        // 如果是admin用户不做处理
        if (userInfo.getRoles().contains("zhhz")) {
            dataCustomerInfo.setOrgId(orgId);
        } else if (userInfo.getRoles().contains("common")) {
            dataCustomerInfo.setOrgId(orgId);
            dataCustomerInfo.setUserId(userId);
        }
        List<DataCustomerInfo> doList = new ArrayList<DataCustomerInfo>();
        doList = dataCustomerInfoMapper.findDataCustomerInfoList(dataCustomerInfo);
        return doList;
    }

    @Override
    public void updateCustomerLatLng(String idCard, String lat, String lng) {
        dataCustomerInfoMapper.updateCustomerLatLng(idCard, lat, lng);
    }

    @Override
    public List<DataCustomerInfo> queryCustomerlatlngEmpty(LoginUser userInfo) {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();
        DataCustomerInfo dataCustomerInfo = new DataCustomerInfo();
        // 如果是admin用户不做处理
        if (userInfo.getRoles().contains("zhhz")) {
            dataCustomerInfo.setOrgId(orgId);
        } else if (userInfo.getRoles().contains("common")) {
            dataCustomerInfo.setOrgId(orgId);
            dataCustomerInfo.setUserId(userId);
        }
        List<DataCustomerInfo> doList = new ArrayList<DataCustomerInfo>();
        doList = dataCustomerInfoMapper.findDataCustomerInfoNotLatAndLng(dataCustomerInfo);
        return doList;
    }
}
